import { _decorator, Component, Node, Prefab, Scheduler, instantiate, director, Label } from 'cc';
import { brid } from './brid';
const { ccclass, property } = _decorator;

@ccclass('gameManager')
export class gameManager extends Component {
	@property(Prefab)
	brid:Prefab = null
	@property(Label)
	scorelabel:Label
	score:number=0
	callback:Function
    start() {
		this.callback=()=>{
			let brids = instantiate(this.brid)
			brids.setParent(this.node)
			brids.setPosition(
				this.node.getPosition().x+Math.random()*210-125,
				15
			)
			// brids.getComponent(brid).fly()
			brids.getComponent(brid).addScoreCallBack=()=>{
				this.score++
				this.scorelabel.string = this.score+''
			}
			brids.getComponent(brid).diecallback=()=>{
				// this.node.destroyAllChildren()
				// this.unschedule(this.callback)
				console.debug('die')
			}
		}
		this.schedule(this.callback,0.1)
    }

    update(deltaTime: number) {
        
    }
}

